<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="decorator" uri="http://claudiushauptmann.com/jsp-decorator/"%>
<%@ page import="vn.fpt.fsoft.entity.User" %>
<decorator:decorate filename="MasterPage.jsp">
	<decorator:content placeholder="title">Amend Government Office Region</decorator:content>
	<decorator:content placeholder="head">
		<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
		<link href="css/style-1.css" rel="stylesheet" type="text/css" />
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
		<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
		<script type="text/javascript" src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="http://bootboxjs.com/bootbox.js"></script>
		<link rel="stylesheet" href="css/style-homepage.css" type="text/css">
		<script type="text/javascript">
			function logout(){
				$.ajax({
					url: "UserController?action=logout",
					type: "POST",
					success:function(data){
					},
					error:function(data){
					}
				});
				return true;	
			}
			$(document).ready(function() {
				$("#tabs").tabs();
				$(window).load(function() {
					$.ajax({
						url : "ListGovOfficeRegionController?action=update&govofficeregionid="
							+<%=request.getParameter("govofficeregionid")%>
							+ "&isactive="
							+<%=request.getParameter("isactive")%>,
						type : "GET",
						success : function(data) {
							$("#table").append(data);
						},
						error : function(data) {
							alert("Don't reload!");
						}
					});
				});
			});

			function isValidate() {
				var valid = true;
				var error = "";
				$("#name").css("border-color", "");
				$("#county").css("border-color", "");
				if ($("#name").val() == "") {
					error += "Please input the Government Office Region<br/>";
					document.getElementById("name").style.borderColor = "red";
					valid = false;
				}
				if ($("#county option:selected").val() == "0") {
					error += "Please choose county";
					document.getElementById("county").style.borderColor = "red";
					valid = false;
				}
				if($("#description").val().length > 300){
					error += "Exceed the allowed character";
					document.getElementById("description").style.borderColor = "red";
					valid = false;
				}
				$("#invalid").html(error);
				return valid;
		  	}

			function Click_Save() {
				if (isValidate()) {
				bootbox.confirm("Do you  want to save it?",
					function(result) {
						if (result == true) {
							var id = <%=request.getParameter("govofficeregionid")%>;
							var countyID = $("#county option:selected").val();
							var govOfficeRegionName = $("#name").val();
							var description = $("#description").val();
							$("#invalid").html("");
							$.ajax({
								url : "ListGovOfficeRegionController?action=saveupdate&countyid="+ countyID
									+"&idGov="+<%=request.getParameter("govofficeregionid")%>
									+ "&govname="+ govOfficeRegionName
									+ "&description="+ description,
								type : "GET",
								success : function(data) {
									$("#invalid").html(data);
									$("#invalid").css("color","green");
								},
								error : function(data) {
									alert("fail");
								}
							});
						}
					});
				} 
			}

			function Click_Cancel() {
				window.location.replace("ListGovOfficeRegion.jsp");
			}
		</script>
	</decorator:content>
	<decorator:content placeholder="body">
	<%
		User user = (User) request.getSession().getAttribute("user");
		if(user == null) {
		    response.sendRedirect("login.jsp");
		}
	%>
	
		<p style="color: #0C3; font-size: 24px; font-weight: bold;">Government Office Region Amend</p>
		<div id="tabs" style="width: 795px;">
			<ul>
				<li><a href="#detail1">Amend</a></li>
				<li style="float: right">
					<input type="button" value="Save"onclick="Click_Save();" /> &nbsp;&nbsp; 
					<input type="button"value="Back" onclick="Click_Cancel();" />
				</li>
			</ul>
			<div id="detail1" style="background-color: #EFEFEF;">
				<table id="table" style="width:703px"></table>
				<br /> <br /> <br />
				<p id="invalid" style="color: #F00; font-size: 14px"></p>
			</div>
		</div>
		
	</decorator:content>
</decorator:decorate>